using System;
using System.Text;
using Me.Prettyprint.Hector.Api.Ddl;

namespace Me.Prettyprint.Cassandra.Serializers
{
    /// <summary>
    /// AsciiSerializer is the same as StringSerializer, but uses "US-ASCII"
    /// encoding instead of UTF
    /// </summary>
	public sealed class AsciiSerializer : AbstractSerializer<string>
	{
        private const string US_ASCII = "US-ASCII";
        public static AsciiSerializer Instance = new AsciiSerializer();
        private Encoding charset = null;
        private ASCIIEncoding encoding = new ASCIIEncoding();

        public AsciiSerializer()
        {
            this.charset = Encoding.ASCII;
        }
        public override ComparatorType GetComparatorType()
        {
            return ComparatorType.ASCIITYPE;
        }
        override public ComparatorType ComparatorType
		{
			get
			{
				return ComparatorType.ASCIITYPE;
			}
			
		}
        public override byte[] ToBytes(string obj)
        {
            return encoding.GetBytes(obj.ToCharArray());
        }
        public override Utils.ByteBuffer ToByteBuffer(string obj)
        {
            return new Utils.ByteBuffer(ToBytes(obj));
        }
        public override string FromBytes(byte[] bytes)
        {
            return encoding.GetString(bytes);
        }
        public override string FromByteBuffer(Utils.ByteBuffer buff)
        {
            return FromBytes(buff.GetBuffer());
        }
	}
}